'use strict';

/**
 * @ngdoc service
 * @name jgappApp.openFile
 * @description
 * # openFile
 * Service in the jgappApp.
 */
angular.module('jgappApp')
    .service('OpenFile', function(DataService, $q, openApi) {
        // AngularJS will instantiate a singleton by calling "new" on this function
        var OpenFile = {};
        OpenFile.open = function(filename) {
            var url = openApi.getPreviewUrl + filename + ".do"
            var defer = $q.defer();
            DataService.getData(url).then(function(data) {
                if (data) {
                    window.open(data, '_system', 'location=no');
                    defer.resolve(data);
                }
            })
            return defer.promise
        }
        return OpenFile
    });
